package com.aismy.admin.service.impl;

import com.aismy.admin.entity.QuestionOption;
import com.aismy.admin.mapper.QuestionOptionMapper;
import com.aismy.admin.service.QuestionOptionService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class QuestionOptionServiceImpl extends ServiceImpl<QuestionOptionMapper, QuestionOption> implements QuestionOptionService {

    @Override
    public List<QuestionOption> getOptionsByQuestionId(Long questionId) {
        return list(new LambdaQueryWrapper<QuestionOption>()
                .eq(QuestionOption::getQuestionId, questionId)
                .orderByAsc(QuestionOption::getSort));
    }

    @Override
    @Transactional
    public void addOption(Long questionId, QuestionOption option) {
        option.setQuestionId(questionId);
        save(option);
    }

    @Override
    @Transactional
    public void updateOption(Long questionId, QuestionOption option) {
        option.setQuestionId(questionId);
        updateById(option);
    }

    @Override
    @Transactional
    public void deleteOption(Long questionId, Long optionId) {
        remove(new LambdaQueryWrapper<QuestionOption>()
                .eq(QuestionOption::getQuestionId, questionId)
                .eq(QuestionOption::getId, optionId));
    }
} 